<template>
	<view class="jnpf-wrap jnpf-wrap-workflow">
		<addForm v-show="addStatus" ref="addFormRef" />
		<view v-show="!addStatus">
			<u-form :model="dataForm" ref="dataForm" :errorType="['toast']" label-position="left" label-width="150"
				label-align="left">
				<u-form-item label="报销编号" v-if="judgeShow('ta002')">
					<u-input v-model="dataForm.ta002" disabled></u-input>
				</u-form-item>
				<u-form-item label="报销日期" v-if="judgeShow('ta004')">
					<u-input v-model="dataForm.ta004" disabled></u-input>
					<lys-date v-if="showta004" type="1" @cancleTime="showta004 = false"
						@submitTime="submitta004"></lys-date>
					<view style="display: flex; justify-content: space-between; width: 100%">
						<view>
							{{ dataForm.ta004 }}
						</view>
						<view>
							<u-icon name="arrow-down-fill" color="#ccc" @click="showta004 = true"
								:disabled="judgeWrite('ta004')||setting.readonly"></u-icon>
						</view>
					</view>
				</u-form-item>
				<u-form-item label="报销" v-if="judgeShow('ta006')">
					<u-radio-group v-model="dataForm.ta006" :disabled="judgeWrite('ta006')||setting.readonly">
						<u-radio v-for="item in ta006Options" :key="item.fullName" :name="item.fullName">
							{{ item.fullName }}
						</u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item label="报销人员" v-if="judgeShow('ta005')">
					<jnpf-user-select v-model="dataForm.ta005" @input="changeName"
						:disabled="judgeWrite('ta005')||setting.readonly" />
				</u-form-item>
				<u-form-item label="报销部门" v-if="judgeShow('ta003')">
					<u-input v-model="dataForm.ta003Name" disabled></u-input>
				</u-form-item>
				<u-form-item label="借款余额" v-if="judgeShow('ta019')">
					<u-input v-model="dataForm.ta019" disabled type="number"></u-input>
				</u-form-item>
				<u-tabs-swiper activeColor="#1890ff" ref="tabs" :list="tabsList" :current="current" @change="change"
					:is-scroll="false" :show-bar="false"></u-tabs-swiper>
				<view class="jnpf-table" style="margin-top: 24rpx" v-show="current == 0">
					<view class="jnpf-table-item" style="margin-bottom: 24rpx"
						v-for="(item, i) in dataForm.tableField115" :key="i">
						<u-form-item label="序号" style="background-color: aqua">
							{{ i + 1 }}
						</u-form-item>
						<u-form-item label="费用申请单单号" v-if="judgeShow('tableField115-tb010')">
							<view style="display: flex; justify-content: space-between; width: 100%">
								<view> {{ item.tb010 }} </view>
								<view>
									<u-icon name="arrow-down-fill" color="#ccc" @click="chioceOastgBox(i)"></u-icon>
								</view>
							</view>
						</u-form-item>
						<u-form-item label="费用类型" v-if="judgeShow('tableField115-tb006')">
							<view style="display: flex; justify-content: space-between; width: 100%">
								<view> {{ item.tb006Name }} </view>
								<view>
									<u-icon name="arrow-down-fill" color="#ccc"
										@click="chioceOastdBox(i, 'tableField115')" :disabled="
                        judgeWrite('tableField115') ||
                          judgeWrite('tableField115-tb006')||setting.readonly
                      "></u-icon>
								</view>
							</view>
						</u-form-item>
						<u-form-item label="金额" v-if="judgeShow('tableField115-tb004')">
							<u-input v-model="item.tb004" type="number" @blur="residueSumChange(item, i)" :disabled="
                      judgeWrite('tableField115') || judgeWrite('tableField115-tb004')||setting.readonly
                    "></u-input>
						</u-form-item>
						<u-form-item label="预算总额" v-if="judgeShow('tableField115-tb013')">
							<u-input v-model="item.tb013" disabled type="number"> </u-input>
						</u-form-item>
						<u-form-item label="剩余额度" v-if="judgeShow('tableField115-tb014')">
							<u-input v-model="item.tb014" disabled type="number"></u-input>
						</u-form-item>
						<u-form-item label="事由" v-if="judgeShow('tableField115-tb015')">
							<u-input v-model="item.tb015" :disabled="
                judgeWrite('tableField115') || judgeWrite('tableField115-tb015')||setting.readonly
              "></u-input>
						</u-form-item>
						<u-form-item label="附件" v-if="judgeShow('tableField115-tb016')">
							<jnpf-file v-model="item.tb016" ref="jnpfFiletb016" :disabled="
                judgeWrite('tableField115') || judgeWrite('tableField115-tb016')||setting.readonly
              " />
						</u-form-item>
						<u-button type="error" plain :ripple="true" @click="delHandleOastbEntityList(i)"
							v-if="!setting.readonly && !judgeWrite('tableField115')">删除</u-button>
					</view>
					<u-button type="primary" @click="addHandleOastbEntityList()"
						v-if="!setting.readonly && !judgeWrite('tableField115')">新增</u-button>
				</view>
				<view class="jnpf-table" style="margin-top: 24rpx" v-show="current == 1">
					<view class="jnpf-table-item" style="margin-bottom: 24rpx" v-for="(item, i) in dataForm.oastjList"
						:key="i">
						<u-form-item label="序号" style="background-color: aqua">
							{{ i + 1 }}
						</u-form-item>
						<u-form-item label="费用类型" v-if="judgeShow('oastjList-tj004')">
							<view style="display: flex; justify-content: space-between; width: 100%">
								<view> {{ item.tj004Name }} </view>
								<view>
									<u-icon name="arrow-down-fill" color="#ccc" @click="chioceOastdBox(i, 'oastjList')"
										:disabled="
                        judgeWrite('oastjList') || judgeWrite('oastjList-tj004')||setting.readonly
                      "></u-icon>
								</view>
							</view>
						</u-form-item>
						<u-form-item label="金额" v-if="judgeShow('oastjList-tj006')">
							<u-input v-model="item.tj006" type=" number" @blur="invoiceChange(item, i)" :disabled="
                      judgeWrite('oastjList') || judgeWrite('oastjList-tj006')||setting.readonly
                    "></u-input>
						</u-form-item>
						<u-form-item label="专票税额" v-if="judgeShow('oastjList-tj007')">
							<u-input v-model="item.tj007" :disabled="
                judgeWrite('oastjList') || judgeWrite('oastjList-tj007')||setting.readonly
              " type="number" @blur="invoiceChange(item, i)"></u-input>
						</u-form-item>
						<u-form-item label="价税合计" v-if="judgeShow('oastjList-tj008')">
							<u-input v-model="item.tj008" disabled type="number"></u-input>
						</u-form-item>
						<u-form-item label="备注" v-if="judgeShow('oastjList-tj009')">
							<u-input v-model="item.tj009" :disabled="
                judgeWrite('oastjList') || judgeWrite('oastjList-tj009')||setting.readonly
              "></u-input>
						</u-form-item>
						<u-form-item label="附件" v-if="judgeShow('oastjList-tj010')">
							<jnpf-file v-model="item.tj010" :disabled="
                judgeWrite('oastjList') || judgeWrite('oastjList-tj010')||setting.readonly
              " />
						</u-form-item>
						<u-button type="error" plain :ripple="true" @click="delHandleOastjEntityList(i)"
							v-if="!setting.readonly && !judgeWrite('oastjList')">删除</u-button>
					</view>
					<u-button type="primary" @click="addHandleOastjEntityList()"
						v-if="!setting.readonly && !judgeWrite('oastjList')">新增</u-button>
				</view>
				<u-form-item label="报销金额合计" v-if="judgeShow('ta020')">
					<u-input v-model="dataForm.ta020" disabled></u-input>
				</u-form-item>
				<u-form-item label="报销金额（大写）" v-if="judgeShow('ta021')">
					<u-input v-model="dataForm.ta021" disabled></u-input>
				</u-form-item>
				<u-form-item label="发票金额合计" v-if="judgeShow('ta022')">
					<u-input v-model="dataForm.ta022" disabled></u-input>
				</u-form-item>
				<u-form-item label="发票金额（大写）" v-if="judgeShow('ta023')">
					<u-input v-model="dataForm.ta023" disabled></u-input>
				</u-form-item>
				<u-form-item label="实际报销额" v-if="judgeShow('ta013')">
					<u-input v-model="dataForm.ta013" :disabled="judgeWrite('ta013')||setting.readonly"
						type="number"></u-input>
				</u-form-item>
				<u-form-item label="支付现金金额" v-if="judgeShow('ta014')">
					<u-input v-model="dataForm.ta014" :disabled="judgeWrite('ta014')||setting.readonly" type="number"
						@blur="paycCashChange"></u-input>
				</u-form-item>
				<u-form-item label="退还预支款金额" v-if="judgeShow('ta015')">
					<!-- 	<u-input v-model="dataForm.ta015" :disabled="judgeWrite('ta015')||setting.readonly" type="number"
						@blur="refundSumChange"></u-input> -->
					<u-search v-model="dataForm.ta015" :disabled="judgeWrite('ta015') ||setting.readonly"
						bg-color="#fff" search-icon='' placeholder='退还预支款金额' @custom="getRefund" @search='getRefund'
						@blur="refundSumChange"></u-search>
				</u-form-item>
				<u-form-item label="收款人（单位）" v-if="judgeShow('ta016')">
					<u-search v-model="dataForm.ta016" :disabled="judgeWrite('ta016') ||setting.readonly"
						bg-color="#fff" search-icon='' placeholder='收款人(单位)' @custom="getPersonBankInfo"
						@search='getPersonBankInfo'></u-search>
				</u-form-item>
				<u-form-item label="开户行" v-if="judgeShow('ta017')">
					<u-input v-model="dataForm.ta017" :disabled="judgeWrite('ta017')||setting.readonly"></u-input>
				</u-form-item>
				<u-form-item label="银行账户" v-if="judgeShow('ta018')">
					<u-input v-model="dataForm.ta018" :disabled="judgeWrite('ta018')||setting.readonly"></u-input>
				</u-form-item>
			</u-form>
		</view>
		<u-popup v-model="popupshow" mode="bottom" height="50vh">
			<view class="content">
				<scroll-view scroll-y="true" style="height: 800rpx">
					<zsf-table :radio="true" @getRow="getSelectData" ref="product" :title="productionQueueTitle"
						:data="tf004List"></zsf-table>
				</scroll-view>
				<view class="confrim-btn">
					<u-button @click="close">确定</u-button>
				</view>
			</view>
		</u-popup>
		<u-popup v-model="oastgBoxVisible" mode="bottom" height="50vh">
			<view class="content">
				<scroll-view scroll-y="true" style="height: 800rpx">
					<zsf-table :radio="true" @getRow="selectOastgList" ref="product" :title="OastgTitle"
						:data="OastgList"></zsf-table>
				</scroll-view>
				<view class="confrim-btn">
					<u-button @click="oastgBoxClose">确定</u-button>
				</view>
			</view>
		</u-popup>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import addForm from "./addForm.vue";
	import comMixin from "../mixin";
	import {
		getGoodsList,
		getCustomerList,
		Info,
		Create,
		Update,
	} from "@/api/apply/order";
	import {
		getOasta,
		BomcbListInit,
		putOasta,
		getOastdList,
	} from "@/api/workFlow/flowBefore";
	import {
		getDictionaryDataSelector,
		getDataInterfaceDataInfo,
		getUserAll,
		GetExpenseBudget,
		GetExpenseApplicationsForCurrentUser
	} from "@/api/common";

	export default {
		mixins: [comMixin],
		components: {
			addForm
		},
		computed: {
			getTb019Computed() {
				return (id) => {
					const options = this.options.filter((item) => id.includes(item.id));
					return options.length > 0 ? options[0].fullName : "";
				};
			},
		},
		watch: {
			"dataForm.tableField115": {
				handler(newVal, oldVal) {
					this.realCalculateSum();
				},
				deep: true, //深度监听
			},
			"dataForm.oastjList": {
				handler(newVal, oldVal) {
					this.billCalculateSum();
				},
				deep: true, //深度监听
			},
		},
		data() {
			return {
				oastgBoxVisible: false,
				OastgTitle: [{
						title: "序号",
						key: "sid",
						width: "80",
					},
					{
						title: "单号",
						key: "tg003",
						width: "80",
					},
					{
						title: "类型",
						key: "tk003Name",
						width: "80",
					},
				],
				productionQueueTitle: [{
						title: "序号",
						key: "sid",
						width: "80",
					},
					{
						title: "费用类型编号",
						key: "td001",
						width: "80",
					},
					{
						title: "费用类型名称",
						key: "td002",
						width: "80",
					},
				],
				OastgList: [],
				tf004List: [],
				ta006Options: [],
				ta003: null,
				opType: 0,
				show: false,
				dataForm: {},
				id: "",
				showForm: [],
				formOperatesList: [],
				tb019Options: [],
				tabsList: [{
						name: "真实情况",
					},
					{
						name: "发票情况",
					},
				],
				current: 0,
				addStatus: '',
				showta004: false,
				popupshow: false,
				List: [],
				tj004: "",
				tj004Name: "",
				tb006: "",
				tb006Name: "",
				oastgDataList: [],
				tb010: null,
			};
		},

		methods: {
			getta006Options() {
				getDictionaryDataSelector("594052415976791365").then((res) => {
					this.ta006Options = res.data.list;
				});
			},
			getRefund() {
				let config = {
					oastoList: this.dataForm.oastoList,
					ta005: this.dataForm.ta005,
					isAdd: false,
				}
				uni.setStorageSync('refundObject', JSON.stringify(config));
				this.$nextTick(() => {
					uni.navigateTo({
						url: `/pages/workFlow/workFlowForm/oasta/com/refund`
					});
				})
			},
			getPersonBankInfo() {
				uni.navigateTo({
					url: `/pages/workFlow/workFlowForm/oasta/com/index`
				});
			},
			addHandleOastjEntityList() {
				let item = {
					tj003: null,
					tj004: null,
					tj006: 0,
					tj007: 0,
					tj008: 0,
					tj009: null,
					tj010: [],
					tj004Name: null,
				};
				this.dataForm.oastjList.push(item);
			},
			// 删除
			delHandleOastjEntityList(index) {
				uni.showModal({
					title: "提示",
					content: "您确定要删除当前数据吗？",
					success: (res) => {
						if (res.confirm) {
							this.dataForm.oastjList.splice(index, 1);
							this.$u.toast(`删除了发票情况第${index + 1}条`);
						}
					},
				});
			},
			addHandleOastbEntityList() {
				if (!this.dataForm.ta005) {
					return this.$refs.uToast.show({
						title: "报销人员不能为空！",
						type: "error",
					});
				}
				if (!this.dataForm.ta003) {
					return this.$refs.uToast.show({
						title: "报销部门不能为空！",
						type: "error",
					});
				}
				if (!this.dataForm.ta004) {
					return this.$refs.uToast.show({
						title: "报销日期不能为空！",
						type: "error",
					});
				}
				let item = {
					tb003: null,
					tb004: 0,
					tb005: null,
					tb006: null,
					tb007: null,
					tb008: 0,
					tb009: 0,
					tb010: null,
					tb011: 0,
					tb012: 0,
					tb006Name: null,
					tb013: 0,
					tb014: 0,
					tb015: null,
					tb016: [],
				};
				this.dataForm.tableField115.push(item);

			},
			// 删除
			delHandleOastbEntityList(index) {
				uni.showModal({
					title: "提示",
					content: "您确定要删除当前数据吗？",
					success: (res) => {
						if (res.confirm) {
							this.dataForm.tableField115.splice(index, 1);
							this.$u.toast(`删除了真实情况的第${index + 1}条`);
							this.dataForm.tableField115.forEach((item, index) => {
								let jnpfFile = 'jnpfFiletb016' + index
								this.$refs[jnpfFile][0].$refs.lsjUpload.show()
							})
						}
					},
				});
			},

			//真实情况 选择费用申请单
			oastgBoxClose() {
				this.oastgBoxVisible = false;
				let list = [{
					...this.oastgDataList,
				}, ];
				console.log('list', list);
				this.dataForm.tableField115.splice(this.index, 1);
				for (let i = 0; i < list.length; i++) {
					const e = list[i];
					var queryParam = {
						te003: this.dataForm.ta003, //部门
						te005: this.dataForm.ta004, //日期
						tf004: e.tk003, //费用类型
					};
					GetExpenseBudget(queryParam).then((res) => {
						let item = {
							tb004: 0, //金额
							tb006: e.tk003, //费用类型（选会计科目树形图，只能选末级）
							tb006Name: e.tk003Name,
							tb010: this.tb010, //费用申请单单号（可以取单）
							tb013: res.data.sumTf005, //预算总金额
							tb014: res.data.residualCredit, //剩余额度
						};
						this.dataForm.tableField115.push(item);
						console.log('this.dataForm.tableField115', this.dataForm.tableField115);
					});
				}
			},
			getSelectData(e) {
				if (this.current == 0) {
					this.List = [{
						...e.data,
					}];
					console.log('e', e);
					this.tb006 = e.data.td001;
					this.tb006Name = e.data.td002;
				} else {
					this.tj004 = e.data.td001;
					this.tj004Name = e.data.td002;
				}
			},
			// 真实情况点击当行赋值
			selectOastgList(e) {
				this.oastgDataList = e.data;
				this.tb010 = e.data.tg003
			},
			// 真实/发票，费用类型确认按钮
			close() {
				this.popupshow = false;
				if (this.current == 0) {
					this.dataForm.tableField115.splice(this.index, 1);
					for (let i = 0; i < this.List.length; i++) {
						const e = this.List[i];
						var queryParam = {
							te003: this.dataForm.ta003, //部门
							te005: this.dataForm.ta004, //日期
							tf004: e.td001, //费用类型
						};
						GetExpenseBudget(queryParam).then((res) => {
							let item = {
								tb004: 0, //金额
								tb006: e.td001, //费用类型
								tb006Name: e.td002,
								tb010: this.tb010, //费用申请单单号（可以取单）
								tb013: res.data.sumTf005, //预算总金额
								tb014: res.data.residualCredit, //剩余额度
							};
							this.dataForm.tableField115.push(item);
							this.dataForm.tableField115[this.index].tb006Name = this.tb006Name;
							this.dataForm.tableField115[this.index].tb006 = this.tb006;
							console.log('this.dataForm.tableField115', this.dataForm.tableField115);
						});
					}
				} else {
					this.dataForm.oastjList[this.index].tj004Name = this.tj004Name;
					this.dataForm.oastjList[this.index].tj004 = this.tj004;

				}
			},
			chioceOastdBox(index, type) {
				if (!this.dataForm.ta003) {
					this.$refs.uToast.show({
						title: "部门不能为空！",
						type: "error",
					});
					return;
				}
				this.index = index; //当前下标
				console.log("当前下标this.index", this.index);
				//报销部门
				var queryParam = {
					td006: this.dataForm.ta003,
					currentPage: 1,
					pageSize: 500,
					sort: "asc",
					sidx: "TD001",
				};
				getOastdList(queryParam).then((res) => {
					this.popupshow = true;
					this.tf004List = res.data.list.map((item, index) => {
						return {
							sid: index + 1,
							...item,
						};
					});
				});
			},
			submitta004(time, type, timeInt) {
				let ta004 = time.split("-");
				this.dataForm.ta004 = ta004[0] + ta004[1] + ta004[2];
				this.showta004 = false;
			},
			changeName(id) {
				console.log("id===>", id);
				getUserAll().then((res) => {
					let item = res.data.filter((o) => o.id === id)[0];
					console.log("item===>", item);
					this.dataForm.ta003 = item.departmentId; //部门编号
					this.ta003 = item.id;
					this.dataForm.ta024 = item.department; //部门名称
					this.dataForm.ta003Name = item.department; //部门名称
				});
			},

			//获取费用申请单列表
			chioceOastgBox(index) {
				var queryParam = {
					tg002: this.ta003,
					currentPage: 1,
					pageSize: 500,
					sort: "asc",
					sidx: "TG001",
				};
				this.index = index; //当前下标
				this.oastgBoxVisible = true;
				GetExpenseApplicationsForCurrentUser(queryParam).then((res) => {
					this.OastgList = res.data.list.map((item, index) => {
						return {
							sid: index + 1,
							...item,
						};
					});
				});
			},
			//借款余额或实际报销额改变时
			actualAndLoanChange() {
				//退款支款金额
				let isAdd = !this.dataForm.ta001 ? true : false;
				if (isAdd) {
					if (parseFloat(this.dataForm.ta013) < parseFloat(this.dataForm.ta019)) {
						this.dataForm.ta015 = parseFloat(this.dataForm.ta013).toFixed(2);
					} else {
						this.dataForm.ta015 = parseFloat(this.dataForm.ta019).toFixed(2);
					}
				}
				this.refundSumChange();
			},
			//退还预支款金额改变时
			refundSumChange() {
				//支付现金金额=实际报销额-退还预支款金额
				this.dataForm.ta014 = this.roundToDecimal(parseFloat(this.dataForm.ta013 || 0) -
					parseFloat(this.dataForm.ta015 || 0))

			},
			//支付现金金额改变时
			paycCashChange() {
				//退还预支款金额=实际报销额-支付现金金额
				this.dataForm.ta015 = this.roundToDecimal(parseFloat(this.dataForm.ta013 || 0) -
					parseFloat(this.dataForm.ta014 || 0));
			},
			//获取真实情况-单身金额的金额合计
			realCalculateSum() {
				let total = 0;
				this.dataForm.tableField115.forEach((item) => {
					let tb004 = item.tb004 && !isNaN(item.tb004) ? Number(item.tb004) : 0;
					total = total + tb004;
				});
				this.$set(this.dataForm, "ta020", this.roundToDecimal(total));
				var ta021 = this.jnpf.capAmountToString(this.dataForm.ta020);
				this.$set(this.dataForm, "ta021", ta021);
				var ta013 = this.roundToDecimal(this.dataForm.ta020);
				this.$set(this.dataForm, "ta013", ta013);
				this.actualAndLoanChange();
			},
			//获取发票情况-单身金额的金额合计
			billCalculateSum() {
				let total = 0;
				this.dataForm.oastjList.forEach((item) => {
					let tj008 = item.tj008 && !isNaN(item.tj008) ? Number(item.tj008) : 0;
					total = total + tj008;
				});
				this.dataForm.ta022 = this.roundToDecimal(total);
				this.$set(this.dataForm, "ta022", this.roundToDecimal(total));
				var ta023 = this.jnpf.capAmountToString(this.dataForm.ta022);
				this.dataForm.ta023 = ta023;
				this.$set(this.dataForm, "ta023", ta023);
			},
			//计算剩余额度
			residueSumChange(row, i) {
				if (parseFloat(row.tb013) >= parseFloat(row.tb004)) {
					//剩余额度=预算总额-金额
					this.dataForm.tableField115[i].tb014 = this.roundToDecimal(parseFloat(row.tb013) - parseFloat(row
						.tb004));
				} else {
					this.dataForm.tableField115[i].tb014 = 0;
				}

			},
			roundToDecimal(num) {
				return parseFloat(num).toFixed(2);
			},
			//计算价税合计
			invoiceChange(row, i) {
				console.log("this.oastjList[i].tj008", this.dataForm.oastjList[i].tj008);
				//价税合计=金额+专票税额
				this.dataForm.oastjList[i].tj008 =
					this.roundToDecimal(parseFloat(row.tj006 || 0) + parseFloat(row.tj007 || 0));
			},
			selectPersonBankInfoList(data) {
				this.dataForm.ta016 = data.ta016; //收款人（单位）
				this.dataForm.ta017 = data.ta017; //开户行
				this.dataForm.ta018 = data.ta018; //银行账户
			},
			init(data, id, flowFormContentJson, addStatus) {
				this.addStatus = addStatus
				this.opType = data.opType;
				this.setting = data;
				console.log('this.setting', this.setting);
				this.formOperatesList = data.formOperates;
				this.id = id;
				if (!this.addStatus) {
					this.getInfoFn(id);
				} else {
					this.$refs.addFormRef.getInfoFn(data)
				}
				uni.$on('updateta016', (data) => {
					this.selectPersonBankInfoList(data)
				})
			},
			getInfoFn(id) {
				getOasta(id).then((res) => {
					if (res.code == 200) {
						this.dataForm = res.data;
						this.changeName(this.dataForm.ta005);
						this.getta006Options()
						// this.getDataInterfaceDataInfoME001(this.dataForm.tg002);
						// this.getDataInterfaceDataInfoMV001(this.dataForm.tg011);
					}
				});
			},
			judgeShow(id) {
				if (!this.setting.formOperates || !this.setting.formOperates.length)
					return true;
				let arr = this.setting.formOperates.filter(o => o.id === id) || [];
				if (!arr.length) return true;
				let item = arr[0];
				return item.read;
			},
			judgeWrite(id) {
				if (!this.setting.formOperates || !this.setting.formOperates.length)
					return false;
				let arr = this.setting.formOperates.filter(o => o.id === id) || [];
				if (!arr.length) return true;
				let item = arr[0];
				return !item.write;
			},
			change(e) {
				this.current = e;

			},
			queryChildBachelor(tb004) {
				let query = {
					tb004,
				};
				BomcbListInit(query).then((res) => {
					this.showForm = res.data;
					this.show = true;
				});
			},
			//  申请人
			getDataInterfaceDataInfoME001(id) {
				let data = {
					id,
					interfaceId: "445425382452126213",
					propsValue: "MV001",
					relationField: "JoinStr",
				};
				getDataInterfaceDataInfo("445425382452126213", data).then((res) => {
					this.dataForm.tg002 = res.data.JoinStr;
				});
			},
			// 部门
			getDataInterfaceDataInfoMV001(id) {
				let data = {
					id,
					interfaceId: "362111557984852549",
					propsValue: "ME001",
					relationField: "JoinStr",
				};
				getDataInterfaceDataInfo("362111557984852549", data).then((res) => {
					this.dataForm.tg011 = res.data.JoinStr;
				});
			},
			selfGetInfo() {
				Info(this.setting.id).then((res) => {
					this.dataForm = res.data;
					if (this.dataForm.fileJson) {
						this.fileList = JSON.parse(this.dataForm.fileJson);
					}
				});
			},
			//单身验证
			verify() {
				console.log("this.dataForm", this.dataForm);
				let isOk = true;
				this.dataForm.ta025 = "N"; //默认未超预算
				//真实情况
				for (let i = 0; i < this.dataForm.tableField115.length; i++) {
					const e = this.dataForm.tableField115[i];
					console.log('e', e);
					if (this.jnpf.isEmpty(e.tb004)) {
						this.$refs.uToast.show({
							title: "真实情况-金额不能为空！",
							type: "error",
						});
						isOk = false;
						break;
					}
					if (e.tb016 == null) this.dataForm.tableField115[i].tb016 = [];
					if (this.jnpf.isEmpty(e.tb006)) {
						this.$refs.uToast.show({
							title: "真实情况-费用类型不能为空！",
							type: "error",
						});
						isOk = false;
						break;
					}
					//判断金额是否超出剩余额度
					if (parseFloat(e.tb004 || 0) > parseFloat(e.tb014 || 0)) {
						this.dataForm.ta025 = "Y"; //超预算
					}
				}
				//发票情况
				for (let i = 0; i < this.dataForm.oastjList.length; i++) {
					const e = this.dataForm.oastjList[i];
					if (this.jnpf.isEmpty(e.tj007) || this.jnpf.isEmpty(e.tj006)) {
						this.$refs.uToast.show({
							title: "发票情况-金额/专票税额不能为空",
							type: "error",
						});
						isOk = false;
						break;
					}
					if (e.tj010 == null) this.dataForm.oastjList[i].tj010 = [];
					if (this.jnpf.isEmpty(e.tj004)) {
						this.$refs.uToast.show({
							title: "发票情况-费用类型不能为空",
							type: "error",
						});

						isOk = false;
						break;
					}
				}
				return isOk;
			},
			submit(eventType, config) {
				console.log('config===>', config);
				if (this.verify && !this.verify()) return;
				if (this.dataForm.ta020 != this.dataForm.ta022) {
					return this.$refs.uToast.show({
						title: "[发票金额合计]必须与[报销金额合计]一致",
						type: "error",
					});
				}
				if (this.jnpf.isEmpty(this.dataForm.ta015)) {
					return this.$refs.uToast.show({
						title: "退还预支款金额不能为空",
						type: "error",
					});
				}
				this.dataForm.flowId = config.flowId
				this.dataForm.flowState = eventType === "submit" ? 0 : 1;
				let name = eventType === "submit" ? '提交' : '保存';
				if (eventType === "audit" || eventType === "reject") {
					this.$emit("eventReceiver", this.dataForm, eventType);
					return;
				}
				uni.showModal({
					title: "提示",
					content: `您确定要${name}当前流程吗？`,
					success: (res) => {
						if (res.confirm) {
							this.selfHandleRequest();
						}
					},
				});
			},
			selfHandleRequest(flowId) {
				console.log('this.dataForm', this.dataForm);
				putOasta(this.dataForm.ta001, this.dataForm).then((res) => {
					uni.showToast({
						title: res.msg,
						complete: () => {
							setTimeout(() => {
								uni.$emit("refresh");
								uni.navigateBack();
							}, 1500);
						},
					});
				});
			},
			initData() {
				getGoodsList().then((res) => {
					this.goodsOptions = res.data.list;
				});
				getCustomerList().then((res) => {
					this.customerOptions = res.data.list;
				});
			},
			selfInit() {
				this.addGoods();
				this.addPlan();
			},
			onChange(e) {
				const user = e[0];
				this.dataForm.salesmanName = user.fullName;
			},
			addGoods() {
				const item = {
					goodsId: "",
					goodsCode: "",
					goodsName: "",
					specifications: "",
					unit: "",
					qty: "",
					price: "",
					amount: "",
					discount: null,
					cess: null,
					actualPrice: "",
					actualAmount: "",
					description: "",
				};
				this.dataForm.goodsList.push(item);
			},
			delGoods(index) {
				this.dataForm.goodsList.splice(index, 1);
			},
			addPlan() {
				const item = {
					receivableDate: "",
					receivableRate: "",
					receivableMoney: "",
					receivableMode: "",
					abstract: "",
				};
				this.dataForm.collectionPlanList.push(item);
			},
			delPlan(index) {
				this.dataForm.collectionPlanList.splice(index, 1);
			},
			onGoodsChange(e, i) {
				const goods = e[0];
				this.dataForm.goodsList[i] = {
					goodsId: goods.id,
					goodsCode: goods.code,
					goodsName: goods.text,
					specifications: goods.specifications,
					unit: goods.unit,
					qty: 1,
					price: goods.price,
					amount: goods.price,
					discount: 100,
					cess: 0,
					actualPrice: goods.price,
					actualAmount: goods.price,
					description: "",
				};
				this.$forceUpdate();
			},
			onCustomerChange(e) {
				const customer = e[0];
				this.dataForm.customerName = customer.text;
			},
			count(row) {
				//金额 = 数量*单价
				row.amount = this.jnpf.toDecimal(
					parseFloat(row.price) * parseFloat(row.qty)
				);
				//折扣价 = (单价*折扣)
				var discountPrice = row.price * (row.discount / 100);
				//实际单价 = 折扣价 * (1 + (税率 / 100))
				row.actualPrice = this.jnpf.toDecimal(
					discountPrice * (1 + row.cess / 100)
				);
				//实际金额
				row.actualAmount = this.jnpf.toDecimal(
					parseFloat(row.actualPrice) * parseFloat(row.qty)
				);
				this.$forceUpdate();
			},
		},
	};
</script>